package test1;

import java.util.*;

public class ball {

    static class Ball implements Comparable<Ball> {
        int energy; // 能量值
        int score; // 击败球球可以获得的得分
        int cnt; // 已击败的球球数

        public Ball(int energy, int score) {
            this.energy = energy;
            this.score = score;
            this.cnt = 0;
        }

        @Override
        public int compareTo(Ball other) {
            return Integer.compare(other.energy, this.energy); // 按照能量值从大到小排序
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        List<Ball> balls = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            balls.add(new Ball(scanner.nextInt(), scanner.nextInt()));
        }
        scanner.close();
        Collections.sort(balls); // 将球球按照能量值从大到小排序
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = balls.get(i).score; // 初始时每个球球只能得到自己的得分
            for (int j = i - 1; j >= 0 && balls.get(i).cnt < m; j--) {
                if (balls.get(j).cnt >= m || balls.get(i).energy <= balls.get(j).energy) {
                    continue; // 跳过无法击败或已经击败了m个球球的球球
                }
                balls.get(j).cnt++; // 标记j为已击败的球球
                res[i] += balls.get(j).score; // 累加得分
            }
        }
        for (int i = n - 1; i >= 0; i--) {
            System.out.print(res[i] + " ");
        }
        System.out.println();
    }
}




